<template>
    <div class="city_wrapper">
      <city-header v-on="$listeners"></city-header>
      <city-search :groupcity="groupcity" v-on="$listeners"></city-search>
      <city-list :hotcity="hotcity" :groupcity="groupcity" :letter="letter" v-on="$listeners"></city-list>
      <city-alphabet :groupcity="groupcity" @change="handleLetterChange"></city-alphabet>
    </div>
</template>

<script>
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      guessCity: '', // 当前城市
      guessCityId: '', // 当前城市id
      hotcity: [], // 热门城市列表
      groupcity: {}, // 所有城市列表
      letter: ''
    }
  },
  mounted () {
    // 获取当前城市
    this.$api.home.cityGuess().then(res => {
      this.guessCity = res.data.name
      this.guessCityId = res.data.id
    })

    // 获取热门城市
    this.$api.home.hotcity().then(res => {
      this.hotcity = res.data
    })

    // 获取所有城市
    this.$api.home.groupcity().then(res => {
      this.groupcity = res.data
    })
  },
  methods: {
    handleLetterChange (letter) {
      this.letter = letter
    }
  }
}
</script>

<style lang="stylus" scoped>
  .city_wrapper
    position: fixed
    top: 0
    left: 0
    right: 0
    bottom: 0
    background: #fff
    z-index: 98
</style>
